package leetcode.剑指offer;

public class 树的子结构26 {
    //判断B是否是A的子结构
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if(A == null || B == null)
            return false;
        return isSameTree(A,B) || isSubStructure(A.left,B) || isSubStructure(A.right,B);
    }

    private boolean isSameTree(TreeNode root, TreeNode subRoot) {
        if(root == null && subRoot == null)
            return true;
        if(subRoot == null)
            return true;
        if(root == null)
            return false;
        if(root.val != subRoot.val)
            return false;
        return isSameTree(root.left,subRoot.left) && isSameTree(root.right,subRoot.right);

    }


}
